/**
 * There are <a href="https://github.com/thinkgem/jeesite">JeeSite</a> code generation
 */
package com.boxin.ims.modules.wechat.web.ask;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.boxin.ims.modules.wechat.entity.ask.AskAnwser;
import com.boxin.ims.modules.wechat.service.ask.AskAnwserService;

/**
 * 疑问解答Controller
 * @author Jakemanse
 * @version 2014-01-03
 */
@Controller
@RequestMapping(value = Global.FRONT_PATH+"/wechat/ask")
public class AskAnwserFrontController extends BaseController {

	@Autowired
	private AskAnwserService askAnwserService;
	
	
	@RequestMapping(value = {"list", ""})
	public String list(AskAnwser askAnwser, HttpServletRequest request, HttpServletResponse response, Model model) {
		
		String uid = request.getParameter("uid");
		try {
			
			
			User user = UserUtils.getUserById(Long.parseLong(uid));
			
			if (!user.isAdmin()){
				askAnwser.setUser(user);
			}
			
			Page<AskAnwser> page = askAnwserService.find(new Page<AskAnwser>(request, response), askAnwser); 
			model.addAttribute("page", page);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "modules/wechat/front/ask/items";
	}
	
	@RequestMapping(value = "detail/{id}")
	public String detail(@PathVariable Long id,	AskAnwser askAnwser, HttpServletRequest request, HttpServletResponse response, Model model) {
		try {
			askAnwser = askAnwserService.get(id);
		} catch (Exception e) {
			
			e.printStackTrace();
		}
		
		model.addAttribute("askAnwser", askAnwser);
		
		return "modules/wechat/front/ask/detail";
	}


}
